package com.allwees.bs.c.module.ops.controller;

import com.allwees.bs.c.module.ops.service.AdvertisementService;
import com.allwees.bs.core.model.ops.AdsModel;
import com.allwees.bs.core.model.ops.constant.AdPositionEnum;
import com.allwees.bs.core.modelbase.vo.R;
import com.allwees.core.common.constant.EPlatform;
import com.allwees.core.common.util.http.RequestContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * C端广告位
 * @Author Daniel
 * @Version 1.0.0
 * @CreateTime 2020/10/16 11:28
 */
@RestController
@RequestMapping("/api/v1/ads")
public class AdsController {

    @Resource
    private AdvertisementService advertisementService;

    /**
     * 获取指定平台的广告位
     * @param code     广告位
     * @return
     */
    @GetMapping("/{position}/{platform}")
    public R adss(@PathVariable("position") int code){
        return ads(code);
    }

    @GetMapping("/{position}")
    public R ads(@PathVariable("position") int code){
        AdPositionEnum position = AdPositionEnum.getByCode(code);
        EPlatform ePlatform = RequestContext.getPlatform();
        if (position == null || ePlatform == EPlatform.UNKNOWN) {
            return R.ok();
        }

        AdsModel model = new AdsModel();
        model.setPosition(position);
        model.setPlatform(ePlatform);
        model.setChannelUuid(RequestContext.getChannel());
        return R.ok(advertisementService.list(model));
    }
}
